<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公司费用管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
//公司费用
$tabs=array(
	array('op'=>'list','title'=>'公司费用'),
);
$tousu_types=$this->tousu_types;
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_kuaidisys_kdlist',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['types']=str_array($item['types']);
			foreach($item['types'] as $tv){
				$item['typestitle'] .=$tousu_types[$tv];
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：</br>1、需要开通接口权限后，查询所开通渠道（快递公司），获取各个公司的收费情况！','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'name','title'=>'标识','type'=>'string'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'channeltag','title'=>'渠道类型','type'=>'string'),
			array('name'=>'channeltype','title'=>'计费类型','type'=>'string'),
			array('name'=>'price_one','title'=>'一公斤价格','type'=>'string'),
			array('name'=>'price_two','title'=>'二公斤价格','type'=>'string'),
			array('name'=>'price_three','title'=>'三公斤价格','type'=>'string'),
			array('name'=>'price_more','title'=>'续重价格','type'=>'string'),
			array('name'=>'insured','title'=>'报价费率','type'=>'string'),
		),'batch'=>array(
			array('type'=>'post','url'=>'jy_kuaidisys/kdlist/updata/','title'=>'获取快递公司'),
		)),
		'search_one'=>array('name'=>'title','title'=>'名称','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='updata'){
	$kdlist=$this->model('api')->upkdlist();
	foreach($kdlist as $item){
		$isadd=pdo_get('jy_kuaidisys_kdlist',array('channelid'=>$item['channelId'],'uniacid'=>$_SESSION['uniacid']));
		$update=array(
			'channel_name'=>$item['channel_name'],
			'low_weight'=>$item['low_weight'],
			'limit_weight'=>$item['limit_weight'],
			'package_count'=>$item['package_count'],
			'paozhong'=>$item['paozhong'],
			'open_status'=>$item['open_status'],
			'channeltag'=>$item['channelTag'],
			'channeltype'=>$item['channelType'],
			'allow_add_bill'=>$item['allow_add_bill'],
			'discount'=>$item['discount'],
			'discount_more'=>$item['discount_more'],
			'price_one'=>$item['price_one'],
			'price_two'=>$item['price_two'],
			'price_three'=>$item['price_three'],
			'price_more'=>$item['price_more'],
			'insured'=>$item['insured'],
			'refuse_freight_rate'=>$item['refuse_freight_rate'],
		);
		if($isadd['id']){
			pdo_update('jy_kuaidisys_kdlist',$update,array('channelid'=>$item['channelId'],'uniacid'=>$_SESSION['uniacid']));
		}else{
			$update['uniacid']=$_SESSION['uniacid'];
			$update['channelid']=$item['channelId'];
			$update['title']=$item['channel_name'];
			$update['createtime']=time();
			$this->insert('kdlist',$update);
		}
	}
	exi('获取成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_kuaidisys_kdlist',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}